<html>
<head><meta charset="utf-8"><title>questions about inheriting fields from workspaces · t-cargo · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/index.html">t-cargo</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html">questions about inheriting fields from workspaces</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="208943869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/208943869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mukund Lakshman <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#208943869">(Sep 03 2020 at 09:52)</a>:</h4>
<p>I'm working on implementing the <code>{ workspaces = true }</code> RFC. I had a question and I thought maybe I can just ask here. For context:</p>
<p>RFC: <a href="https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md">https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md</a><br>
Pull Request (WIP): <a href="https://github.com/rust-lang/cargo/pull/8664">https://github.com/rust-lang/cargo/pull/8664</a></p>
<p>How should <code>{ workspace = true }</code> interact with the <code>[patches]</code> and <code>[replace]</code> sections?</p>
<ol>
<li>What should happen if you try to patch a <code>{ workspace = true }</code> dependency? </li>
<li>Can items in the <code>[patch]</code> table specify <code>{ workspace = true }</code>? (I would guess not..)</li>
<li>Same questions, but for <code>[replace]</code></li>
</ol>
<p>Also, hi &amp; nice to meet you all. <span aria-label="wave" class="emoji emoji-1f44b" role="img" title="wave">:wave:</span></p>



<a name="208966289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/208966289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eh2406 <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#208966289">(Sep 03 2020 at 13:28)</a>:</h4>
<p>Hi &amp; thanks for working on this!</p>



<a name="208969478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/208969478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#208969478">(Sep 03 2020 at 13:50)</a>:</h4>
<p>I think it should be fine (if albeit a little weird) to <code>[patch]</code> a <code>{workspace=true}</code> dependency. I believe, based on how Cargo works internally, it shouldn't require any special consideration code-wise. Policy-wise, I don't see a reason to specifically forbid it.</p>
<p>As for specifying <code>{workspace=true}</code> in <code>[patch]</code>, it seems reasonable to forbid that, just because it seems a little confusing. If some use case appears in the future, we could add it, but I can't think of a reason to do that.</p>
<p>I think <code>[replace]</code> could follow the same rules as <code>[patch]</code>.</p>



<a name="208972708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/208972708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#208972708">(Sep 03 2020 at 14:10)</a>:</h4>
<p>I would agree patch and replace tables should follow the same rules, but I would say you should be able to <code>[patch]</code> a dependency listed as <code>workspace = true</code> for sure</p>



<a name="208972746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/208972746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#208972746">(Sep 03 2020 at 14:11)</a>:</h4>
<p>basically <code>[patch]</code> should apply to <code>[workspace.dependencies]</code> as it would to <code>[dependencies]</code></p>



<a name="208973573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/208973573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mukund Lakshman <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#208973573">(Sep 03 2020 at 14:16)</a>:</h4>
<p>That makes sense, thanks for clarifying ^^</p>



<a name="208985878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/208985878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#208985878">(Sep 03 2020 at 15:35)</a>:</h4>
<p>I would also agree that you shouldn't be able to use <code>{ workspace = true }</code> in a patch or replace section, until there's some concrete use case or semantic where that would make sense.</p>



<a name="208986068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/208986068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#208986068">(Sep 03 2020 at 15:37)</a>:</h4>
<p>Also, thank you so much for working on this!</p>



<a name="209342682"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209342682" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mukund Lakshman <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209342682">(Sep 08 2020 at 03:26)</a>:</h4>
<p>Thanks for the encouragement! This is coming along. I had some additional questions that came up. Neither of these things are blocking my implementation, but just thought I'd bubble them up sooner rather than later:</p>
<ol>
<li>The RFC says:</li>
</ol>
<blockquote>
<p>For dev-dependencies where the referenced package is <code>publish = false</code>, then the dependency will be dropped. Otherwise Cargo will assume that <code>version = "$dependency_version"</code> was specified, meaning that it requires at least the current version and otherwise any semver-compatible version."  [a]</p>
</blockquote>
<p>But the reference-level explanation [b] does not distinguish between <code>dev-dependencies</code> and other kinds of dependencies. Is the intended behavior that <code>dev-dependencies</code> behaves differently from other kinds of dependencies? </p>
<p>In addition, how should it behave if <code>publish</code> is a list of registries rather than a bool?</p>
<ol start="2">
<li>Next:<blockquote>
<p>Note that directives like license-file are resolved relative to their definition, so license-file is relative to the [workspace] section that defined it. [c]</p>
</blockquote>
</li>
</ol>
<p>The license-file and readme may be outside the package root. If the license-file is in <code>../../../mukund/private/secret-project/foo</code>, we probably don't want to publish that in the manifest. One possible solution: we could copy the root workspace's file into the package root. This is what we currently do if the <code>license-file</code> lives outside the package root. </p>
<p>[a] <a href="https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md#no-longer-need-both-version-and-path-to-publish-to-cratesio">https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md#no-longer-need-both-version-and-path-to-publish-to-cratesio</a><br>
[b] <a href="https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md#path-dependencies-infer-version-directive">https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md#path-dependencies-infer-version-directive</a><br>
[c] <a href="https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md#placeholder-values">https://github.com/rust-lang/rfcs/blob/master/text/2906-cargo-workspace-deduplicate.md#placeholder-values</a></p>



<a name="209409317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209409317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209409317">(Sep 08 2020 at 16:14)</a>:</h4>
<p><span class="user-mention" data-user-id="332369">@Mukund Lakshman</span> ah I think for your first question I wouldn't distinguish between dev and non-dev dependencies</p>



<a name="209409345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209409345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209409345">(Sep 08 2020 at 16:14)</a>:</h4>
<p>I think I realized later on that there wasn't a need to do that, but I never went back and upated the first part</p>



<a name="209409625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209409625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209409625">(Sep 08 2020 at 16:16)</a>:</h4>
<p>For licenses, I think we <a href="https://github.com/rust-lang/cargo/blob/99134aee3911e7aafeeb645a9d47a7d2e984e2eb/src/cargo/ops/cargo_package.rs#L203-L260">already have some logic</a> for copying the file into the package if it lives outside, so I don't think this RFC affects much of that</p>



<a name="209409645"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209409645" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209409645">(Sep 08 2020 at 16:16)</a>:</h4>
<p>but was there something else you were concerned about?</p>



<a name="209415283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209415283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mukund Lakshman <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209415283">(Sep 08 2020 at 17:02)</a>:</h4>
<p><span class="user-mention" data-user-id="116015">@Alex Crichton</span>  For 1, I am still unsure what to do in this situation:</p>
<div class="codehilite"><pre><span></span><code><span class="c1"># Cargo.toml</span>
<span class="k">[dependencies]</span>
<span class="n">foo</span> <span class="o">=</span> <span class="p">{</span> <span class="n">path</span> <span class="o">=</span> <span class="s">&quot;./foo&quot;</span> <span class="p">}</span>

<span class="c1"># foo/Cargo.toml</span>
<span class="n">version</span> <span class="o">=</span> <span class="mf">1.2.3</span>
<span class="n">publish</span> <span class="o">=</span> <span class="k">[&quot;registry1&quot;]</span>
</code></pre></div>


<p>For now, I'm going to treat an array of registries (<code>publish = [..]</code>) the same as <code>publish = false</code>.</p>
<p>For 2, I think we just need similar logic for readmes that we have for license files. I think I have enough to code it up. </p>
<p>Should have a first draft of the PR ready tonight, if having some code would help disambiguate.</p>



<a name="209415363"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209415363" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209415363">(Sep 08 2020 at 17:02)</a>:</h4>
<p>oh I think I'd treat <code>publish = false</code> as unique, and anything else as "fill in the version"</p>



<a name="209415384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209415384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209415384">(Sep 08 2020 at 17:03)</a>:</h4>
<p>the intention is that <code>[dev-dependencies]</code> with <code>publish=false</code> don't hinder publication</p>



<a name="209415396"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209415396" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209415396">(Sep 08 2020 at 17:03)</a>:</h4>
<p>everything else is just convenience</p>



<a name="209415430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209415430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alex Crichton <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209415430">(Sep 08 2020 at 17:03)</a>:</h4>
<p><code>[dependencies]</code> with <code>publish = false</code> is an error though (and it'll get reported later)</p>



<a name="209415983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/246057-t-cargo/topic/questions%20about%20inheriting%20fields%20from%20workspaces/near/209415983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mukund Lakshman <a href="https://rust-lang.github.io/zulip_archive/stream/246057-t-cargo/topic/questions.20about.20inheriting.20fields.20from.20workspaces.html#209415983">(Sep 08 2020 at 17:08)</a>:</h4>
<p>Okay, that makes sense to me now.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>